package com.yxy.controller;

import com.yxy.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * @author
 * 文件上传下载
 */


@RestController
@RequestMapping("/file")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    //文件上传测试
    @PostMapping("/upload")
    @ResponseBody
    public Map<String, Object>  fileUpload(MultipartFile file) {
        Map<String, Object> map = fileUploadService.uploadFile(file);
        return map;
    }


    //文件上传测试
    @PostMapping("/uploadList")
    @ResponseBody
    public List<Map<String, Object>>  fileUploadList(List<MultipartFile> file) {
        List<Map<String, Object>>  resultList= fileUploadService.uploadFileList(file);
        return resultList;
    }



    //文件查看测试
    @GetMapping("/downloadFile")
    @ResponseBody
    public void  downloadFile(HttpServletResponse response, String fileName) {
        fileUploadService.downloadFile(response,fileName);
    }

}
